<?php
class RecreationsController extends AppController {

	var $name = 'Recreations';
	
	
	function beforeFilter() {
    parent::BeforeFilter();   	
	//$this->Auth->allow('login','logout','userlist','add','confirmaccount');
	//$this->Auth->allow('*');
}

	function index() {
		$this->Recreation->recursive = 0;
		$this->paginate = array(
        'conditions' => array('Recreation.user_id' => $this->Auth->user('id')),
        'limit' => 10
    );
		$this->set('recreations', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid recreation', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('recreation', $this->Recreation->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
		$this->data['Recreation']['user_id']=$this->Auth->user('id');
			$this->Recreation->create();
			if ($this->Recreation->save($this->data)) {
				$this->Session->setFlash(__('The recreation has been saved', true));
				$this->redirect(array('controller' => 'Services','action' => 'index'));
			} else {
				$this->Session->setFlash(__('The recreation could not be saved. Please, try again.', true));
			}
		}
		$users = $this->Recreation->User->find('list');
		$this->set(compact('users'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid recreation', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Recreation->save($this->data)) {
				$this->Session->setFlash(__('The recreation has been saved', true));
				$this->redirect(array('controller' => 'Services','action' => 'index'));
			} else {
				$this->Session->setFlash(__('The recreation could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Recreation->read(null, $id);
		}
		$users = $this->Recreation->User->find('list');
		$this->set(compact('users'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for recreation', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Recreation->delete($id)) {
			$this->Session->setFlash(__('Recreation deleted', true));
			$this->redirect(array('controller' => 'Services','action' => 'index'));
		}
		$this->Session->setFlash(__('Recreation was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>